﻿using System.Runtime.CompilerServices;

namespace System
{
    internal static class FloatExtend
    {
        #pragma warning disable S4136
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe bool IsFinite(double value)
        {
            long bits = BitConverter.DoubleToInt64Bits(value);
            return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
       
        public static unsafe bool IsNegative(double value)
        {
            return BitConverter.DoubleToInt64Bits(value) < 0;
        }
        #pragma warning restore S4136

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static bool IsFinite(float value)
        {
            int bits = SingleToInt32Bits(value);
            return (bits & 0x7FFFFFFF) < 0x7F800000;
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe bool IsNegative(float value)
        {
            return SingleToInt32Bits(value) < 0;
        }


        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static unsafe int SingleToInt32Bits(float value)
        {
            return *((int*)&value);
        }
    }
}
